package sort.primarySort;

import sort.template;

import java.util.Arrays;

import static sort.SortCompare.getArray;

public class Selection extends template {
    public static void sort(Comparable[] a) {
        for (int i = 0; i < a.length; i++) {
            int min_index = i;
            for (int j = i + 1; j < a.length; j++) {
                if (less(a[j], a[min_index])) {
                    min_index = j;
                }
            }
            exch(a, i, min_index);
        }
    }

    public static void main(String[] args) {
        Comparable[] array = getArray(10);
        System.out.println("原来的数组:" + Arrays.asList(array));
        sort(array);
        System.out.println("排序之后的数组为:" + Arrays.asList(array));

    }
}
